# TODO: Add comment
# 
# Author: roger
###############################################################################

setAs("ZeroRateCurve","DiscountFactor",function(from){
			SituationDate <- from@SituationDate
			Currency <- from@Currency
			Name <- from@Name
			Date <- from@Date
			Time <- yearFraction(SituationDate,Date)
			Data <- exp(-1 * from@Data/100 * Time)
			DiscountFactor(SituationDate,Currency,Name,Date,Data)
		})

setMethod("as.DiscountFactor","ZeroRateCurve",function(object){
			as(object,"DiscountFactor")
		})

setAs("DiscountFactor","ZeroRateCurve",function(from){
			SituationDate <- from@SituationDate
			Currency <- from@Currency
			Name <- from@Name
			Date <- from@Date
			Time <- yearFraction(SituationDate,Date)
			Data <- -log(from@Data)/Time * 100
			Data[Date==SituationDate,] <- Data[which(Date==SituationDate)+1,]
			ZeroRateCurve(SituationDate,Currency,Name,Date,Data)
		})

setMethod("as.ZeroRateCurve","DiscountFactor",function(object){
			as(object,"ZeroRateCurve")
		})

setAs("ZeroRateSpread","DiscountFactor",function(from){
			SituationDate <- from@SituationDate
			Currency <- from@Currency
			Name <- from@Name
			Date <- from@Date
			Time <- yearFraction(SituationDate,Date)
			Data <- exp(-1 * from@Data/100 * Time)
			DiscountFactor(SituationDate,Currency,Name,Date,Data)
		})

setMethod("as.DiscountFactor","ZeroRateSpread",function(object){
			as(object,"DiscountFactor")
		})


setAs("DiscountFactor","ZeroRateSpread",function(from){
			SituationDate <- from@SituationDate
			Currency <- from@Currency
			Name <- from@Name
			Date <- from@Date
			Time <- yearFraction(SituationDate,Date)
			Data <- -log(from@Data)/Time * 100
			Data[Date==SituationDate,] <- Data[which(Date==SituationDate)+1,]
			ZeroRateSpread(SituationDate,Currency,Name,Date,Data)
		})

setMethod("as.ZeroRateSpread","DiscountFactor",function(object){
			as(object,"ZeroRateSpread")
		})



